package reduce.fz.com.reduce.activity;

import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import reduce.fz.com.reduce.R;
import reduce.fz.com.reduce.custom.TabIndicator;
import reduce.fz.com.reduce.util.TipUtil;
import reduce.fz.com.reduce.util.base.ReduceApplication;

public abstract class BaseToolBarActivity extends ActionBarActivity {
    public FrameLayout mContainerFrameLayout;
    public Toolbar mToolbar;
    public Boolean isBackIcon=false;
    public int customIcon=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_tool_bar);
        mContainerFrameLayout = (FrameLayout) findViewById(R.id.container);
        // 设置窗口风格为顶部显示Actionbar
        mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
        setSupportActionBar(mToolbar);
        ActionBar actionBar = getSupportActionBar();
            actionBar.setDisplayShowTitleEnabled(false);
        // 决定左上角图标的右侧是否有向左的小箭头, true
        if(isBackIcon)
        {
            actionBar.setDisplayHomeAsUpEnabled(true);

        }else {
            actionBar.setDisplayHomeAsUpEnabled(false);
        }
        // mToolbar.setNavigationIcon(R.drawable.icon_toolbar_selector);
        if(customIcon!=0) {
             mToolbar.setNavigationIcon(customIcon);
        }
        // 使左上角图标是否显示，如果设成false，则没有程序图标，仅仅就个标题，
        //actionBar.setDisplayShowHomeEnabled(false);
        // 否则，显示应用程序图标，对应id为android.R.id.home，对应ActionBar.DISPLAY_SHOW_HOME
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    pressBar();
                } catch (Throwable e) {
                }
            }
        });
        ReduceApplication.getInstance().addActivity(this);
    }

    public  void pressBar(){


    }


   @Override
    public void setContentView(int layoutResID) {
        if (layoutResID == R.layout.activity_base_tool_bar) {//如果是
            super.setContentView(layoutResID);
        } else {
            getLayoutInflater().inflate(layoutResID, mContainerFrameLayout);//否则加入到container
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:// 点击返回图标事件
                this.finish();
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    public abstract void initWidget();

    public abstract void initListener();

    public void toastMsg(String t)
    {

    }





}
